﻿using System.Web.Configuration;
using Shinkansen.Configuration;

namespace Shinkansen.Web
{
    /// <summary>
    /// A sample cryptographic provider which requires full trust.
    /// </summary>
    public class FullTrustMachineKeyProvider : ICryptoKeyProvider
    {
        private readonly MachineKeySection _machineKeySection;

        /// <summary>
        /// Initializes a new instance of the <see cref="FullTrustMachineKeyProvider"/> class.
        /// </summary>
        public FullTrustMachineKeyProvider ()
        {
             _machineKeySection = (MachineKeySection) WebConfigurationManager.GetWebApplicationSection ("system.web/machineKey");
        }

        /// <summary>
        /// Gets the key.
        /// </summary>
        /// <value>The key.</value>
        /// <remarks>The recommended key length is 512 bits.</remarks>
        public string Key
        {
            get { return _machineKeySection.DecryptionKey; }
        }

        /// <summary>
        /// Gets the initialization vector (IV).
        /// </summary>
        /// <value>The IV.</value>
        public string IV
        {
            get { return _machineKeySection.ValidationKey; }
        }
    }
}
